<div [@routerTransition]>

    <div class="m-subheader ">
        <div class="d-flex align-items-center">
            <div class="mr-auto col-xs-6">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>{{l("Roles")}}</span>
                </h3>
                <span class="m-section__sub">
                    {{l("RolesHeaderInfo")}}
                </span>
            </div>
            <div class="col-xs-6 text-right">
                <button (click)="createRole()" *ngIf="isGranted('Pages.Administration.Roles.Create')" class="btn btn-primary blue"><i class="fa fa-plus"></i> {{l("CreateNewRole")}}</button>
            </div>
        </div>
    </div>

    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <div class="m-form m-form--label-align-right">
                    <div class="row m--margin-bottom-10">
                        <div class="col-xl-6">
                            <div class="form-group">
                                <permission-combo [(selectedPermission)]="selectedPermission"></permission-combo>
                            </div>
                        </div>
                        <div class="col-xl-6 text-right">
                            <button name="RefreshButton" class="btn btn-metal" (click)="getRoles()"><i class="la la-refresh"></i> {{l('Refresh')}}</button>
                        </div>
                    </div>
                </div>
                <div class="row align-items-center">
                    <!--<Primeng-Datatable-Start>-->
                    <div class="primeng-datatable-container" [busyIf]="primengDatatableHelper.isLoading">
                        <p-dataTable #dataTable
                                     (onLazyLoad)="getRoles()"
                                     [value]="primengDatatableHelper.records"
                                     rows="{{primengDatatableHelper.defaultRecordsCountPerPage}}"
                                     [paginator]="false"
                                     [lazy]="true"
                                     emptyMessage="{{l('NoData')}}"
                                     [responsive]="primengDatatableHelper.isResponsive">
                            <p-footer>
                                {{l('TotalRecordsCount', primengDatatableHelper.totalRecordsCount)}}
                            </p-footer>

                            <p-column field=""
                                      header="{{l('Actions')}}"
                                      [sortable]="false"
                                      [style]="{'width':'130px','text-align':'center'}"
                                      [hidden]="!isGrantedAny('Pages.Administration.Roles.Edit', 'Pages.Administration.Roles.Delete')">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <div class="btn-group dropdown">
                                        <button class="dropdown-toggle btn btn-brand btn-sm dropdown-toggle btn-primary"
                                                data-toggle="dropdown"
                                                tooltip="{{l('Actions')}}"
                                                aria-haspopup="true"
                                                aria-expanded="false">
                                            <i class="fa fa-cog"></i><span class="caret"></span> {{l("Actions")}}
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a *ngIf="permission.isGranted('Pages.Administration.Roles.Edit')"
                                                   (click)="createOrEditRoleModal.show(record.id)">{{l('Edit')}}</a>
                                            </li>
                                            <li>
                                                <a *ngIf="!record.isStatic && permission.isGranted('Pages.Administration.Roles.Delete')"
                                                   (click)="deleteRole(record)">{{l('Delete')}}</a>
                                            </li>
                                        </ul>
                                    </div>
                                </ng-template>
                            </p-column>
                            <p-column field="displayName" header="{{l('RoleName')}}" [sortable]="false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    <span>
                                        {{record.displayName}}
                                        <span *ngIf="record.isStatic"
                                              class="m-badge m-badge--brand m-badge--wide"
                                              data-toggle="tooltip"
                                              title="{{l('StaticRole_Tooltip')}}"
                                              data-placement="top">
                                            {{l('Static')}}
                                        </span>
                                        <span *ngIf="record.isDefault"
                                              class="m-badge m-badge--metal m-badge--wide"
                                              data-toggle="tooltip"
                                              title="{{l('DefaultRole_Description')}}"
                                              data-placement="top">
                                            {{l('Default')}}
                                        </span>
                                    </span>
                                </ng-template>
                            </p-column>

                            <p-column field="creationTime" header="{{l('CreationTime')}}" [sortable]="false">
                                <ng-template let-record="rowData" pTemplate="body">
                                    {{record.creationTime | momentFormat:'L'}}
                                </ng-template>
                            </p-column>

                        </p-dataTable>

                    </div>
                    <!--<Primeng-Datatable-End>-->
                </div>
            </div>
        </div>
    </div>

    <createOrEditRoleModal #createOrEditRoleModal (modalSave)="getRoles()"></createOrEditRoleModal>
</div>
